import { OperateBase } from '../../common/operate-base';
import { MergeCellPlugin } from '../../../pugins/merge-cell.plugin';
export class Unmerge extends OperateBase {
    protected container: HTMLElement;
    protected plugin: MergeCellPlugin;
    constructor() {
        super();
    }
    public selectChange() {

    }
    public afterDomInit() {
        this.plugin = this.zTableInstance.pluginManager.getPlugin(MergeCellPlugin.pluginName);
        this.zTableInstance.getHook().afterSelect.add(() => {
            this.setDisable();
        });
        this.zTableInstance.getHook().afterCommandExcute.add(() => {
            this.setDisable();
        });
        this.setDisable();
    }
    public getDom() {
        this.container = document.createElement('div');
        this.container.setAttribute('class', this.containerClassName);
        this.container.innerHTML=`<span class="z-tools-icon icon iconfont icon-unmerge1"></span>`;
        let ele = this.container.querySelector('.icon-unmerge1');
        ele.addEventListener('click', () => {
            if(ele.classList.contains('z-table-icon-disabled')) {
                return;
            }
            this.plugin.unmerge();
        });
        return this.container;
    }
    public setDisable() {
        let ele: HTMLElement = this.container.querySelector('.icon-unmerge1');
        if(this.plugin.canUnmerge) {
            ele.classList.remove('z-table-icon-disabled');
        } else {
            ele.classList.add('z-table-icon-disabled');
        }
    }
}